/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.firstpart.location.mapper.OrderStoreDetailMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.firstpart.location.mapper;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.location.entity.OrderStoreDetailEntity;

import java.sql.Types;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class OrderStoreDetailMapperImpl {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;

    public int editEntityFlagByStoreId(String id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update `dxq_orderstoredetail` set `dr`=1 where `dr`=0 and `storeid`=?;\n";
        parameter.addParam(id);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    public OrderStoreDetailEntity selectByPrimaryKey(Integer id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_orderstoredetail where `id` = ?\n";
        parameter.addParamWithType(id, Types.INTEGER);

        ResultSetProcessor processor = new AutoBeanProcessor(new OrderStoreDetailEntity());
        return (OrderStoreDetailEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }


    public int insertSelective(OrderStoreDetailEntity record) {
        
        return 0;
    }


    public int editEntityFlagByMainId(String id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update `dxq_orderstoredetail` set `dr`=1 where `dr`=0 and `mainid`=?;\n";
        parameter.addParam(id);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int updateByPrimaryKeySelective(OrderStoreDetailEntity record) {
        
        return 0;
    }


    public int updateByPrimaryKey(OrderStoreDetailEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxq_orderstoredetail set `storeid` = ?, `dr` = ?, `mainid` = ?, `detailid` = ?, `inventoryowner` = ?, `reserveid` = ?, `orderid` = ?, `orderdetailid` = ?, `sourceid` = ?, `sourceautoid` = ?, `sourcecode` = ?, `firstsourceid` = ?, `firstsourceautoid` = ?, `firstsourcecode` = ?, `unitid` = ?, `stockunitid` = ?, `productid` = ?, `productskuid` = ?, `warehouseid` = ?, `operateuserid` = ?, `operatetime` = ?, `operatetype` = ?, `operatetypename` = ?, `storecount` = ? `epccount` = ? where `id` = ?\n";
        parameter.addParamWithType(record.getStoreid(), Types.VARCHAR);
		parameter.addParamWithType(record.getDr(), Types.SMALLINT);
		parameter.addParamWithType(record.getMainid(), Types.VARCHAR);
		parameter.addParamWithType(record.getDetailid(), Types.VARCHAR);
		parameter.addParamWithType(record.getInventoryowner(), Types.VARCHAR);
		parameter.addParamWithType(record.getReserveid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderdetailid(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourceid(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourceautoid(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourcecode(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourceid(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourceautoid(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourcecode(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitid(), Types.VARCHAR);
		parameter.addParamWithType(record.getStockunitid(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductid(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductskuid(), Types.VARCHAR);
		parameter.addParamWithType(record.getWarehouseid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOperateuserid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOperatetime(), Types.VARCHAR);
		parameter.addParamWithType(record.getOperatetype(), Types.VARCHAR);
		parameter.addParamWithType(record.getOperatetypename(), Types.VARCHAR);
		parameter.addParamWithType(record.getStorecount(), Types.DECIMAL);
		parameter.addParamWithType(record.getEpccount(), Types.INTEGER);
		parameter.addParamWithType(record.getId(), Types.INTEGER);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int insert(OrderStoreDetailEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxq_orderstoredetail (`id`, `storeid`,  `mainid`, `detailid`,  `inventoryowner`, `reserveid`,  `orderid`, `orderdetailid`,  `sourceid`,`sourceautoid`, `sourcecode`,  `firstsourceid`,`firstsourceautoid`, `firstsourcecode`,  `unitid`, `stockunitid`, `productid`,  `productskuid`, `warehouseid`,  `operateuserid`, `operatetime`,  `operatetype`, `operatetypename`,  `storecount`, `epccount`, `dr`) values (?, ?,  ?, ?,  ?, ?,  ?, ?,  ?,?, ?,  ?,?, ?,  ?, ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?, ?)\n";
        parameter.addParamWithType(record.getId(), Types.INTEGER);
		parameter.addParamWithType(record.getStoreid(), Types.VARCHAR);
		parameter.addParamWithType(record.getMainid(), Types.VARCHAR);
		parameter.addParamWithType(record.getDetailid(), Types.VARCHAR);
		parameter.addParamWithType(record.getInventoryowner(), Types.VARCHAR);
		parameter.addParamWithType(record.getReserveid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderdetailid(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourceid(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourceautoid(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourcecode(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourceid(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourceautoid(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourcecode(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitid(), Types.VARCHAR);
		parameter.addParamWithType(record.getStockunitid(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductid(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductskuid(), Types.VARCHAR);
		parameter.addParamWithType(record.getWarehouseid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOperateuserid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOperatetime(), Types.VARCHAR);
		parameter.addParamWithType(record.getOperatetype(), Types.VARCHAR);
		parameter.addParamWithType(record.getOperatetypename(), Types.VARCHAR);
		parameter.addParamWithType(record.getStorecount(), Types.DECIMAL);
		parameter.addParamWithType(record.getEpccount(), Types.INTEGER);
		parameter.addParamWithType(record.getDr(), Types.SMALLINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public List<OrderStoreDetailEntity> selectByOrderId(String mainid) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from `dxq_orderstoredetail` where `mainid`=?;\n";
        parameter.addParam(mainid);

        ResultSetProcessor processor = new AutoBeanListProcessor(new OrderStoreDetailEntity());
        return (List<OrderStoreDetailEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }


    public Integer insertBatch(List<OrderStoreDetailEntity> insertBatch) {
		if (insertBatch == null || insertBatch.size()==0) return 0;
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into dxq_orderstoredetail (`id`, `storeid`, `mainid`, `detailid`, `inventoryowner`, `reserveid`, `orderid`, `orderdetailid`, `sourceid`,`sourceautoid`, `sourcecode`, `firstsourceid`,`firstsourceautoid`, `firstsourcecode`, `unitid`, `stockunitid`, `productid`, `productskuid`, `warehouseid`, `operateuserid`, `operatetime`, `operatetype`, `operatetypename`, `storecount`, `epccount`, `dr`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				OrderStoreDetailEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.INTEGER);
				parameter.addParamWithType(item.getStoreid(), Types.VARCHAR);
				parameter.addParamWithType(item.getMainid(), Types.VARCHAR);
				parameter.addParamWithType(item.getDetailid(), Types.VARCHAR);
				parameter.addParamWithType(item.getInventoryowner(), Types.VARCHAR);
				parameter.addParamWithType(item.getReserveid(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrderid(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrderdetailid(), Types.VARCHAR);
				parameter.addParamWithType(item.getSourceid(), Types.VARCHAR);
				parameter.addParamWithType(item.getSourceautoid(), Types.VARCHAR);
				parameter.addParamWithType(item.getSourcecode(), Types.VARCHAR);
				parameter.addParamWithType(item.getFirstsourceid(), Types.VARCHAR);
				parameter.addParamWithType(item.getFirstsourceautoid(), Types.VARCHAR);
				parameter.addParamWithType(item.getFirstsourcecode(), Types.VARCHAR);
				parameter.addParamWithType(item.getUnitid(), Types.VARCHAR);
				parameter.addParamWithType(item.getStockunitid(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductid(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductskuid(), Types.VARCHAR);
				parameter.addParamWithType(item.getWarehouseid(), Types.VARCHAR);
				parameter.addParamWithType(item.getOperateuserid(), Types.VARCHAR);
				parameter.addParamWithType(item.getOperatetime(), Types.VARCHAR);
				parameter.addParamWithType(item.getOperatetype(), Types.VARCHAR);
				parameter.addParamWithType(item.getOperatetypename(), Types.VARCHAR);
				parameter.addParamWithType(item.getStorecount(), Types.DECIMAL);
				parameter.addParamWithType(item.getEpccount(), Types.INTEGER);
				parameter.addParamWithType(item.getDr(), Types.SMALLINT);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int deleteByPrimaryKey(Integer id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxq_orderstoredetail where `id` = ?\n";
        parameter.addParamWithType(id, Types.INTEGER);

        
        return ymsJdbcApi.update(sql, parameter);
    }

}
